package com.ruoyi.yyq.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.yyq.domain.CarRepairReservation;
import com.ruoyi.yyq.service.ICarRepairReservationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 维修预约Controller
 * 
 * @author ruoyi
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/reservation")
@CrossOrigin
public class CarRepairReservationController extends BaseController
{
    @Autowired
    private ICarRepairReservationService carRepairReservationService;

//  对外暴露接口  查询维修预约列表
    @InnerAuth
    @GetMapping("/getlist")
    public TableDataInfo getlist(CarRepairReservation carRepairReservation)
    {
        startPage();
        List<CarRepairReservation> list = carRepairReservationService.selectCarRepairReservationList(carRepairReservation);
        System.out.println(list.toString());
        return getDataTable(list);
    }
//  对外暴露接口  添加维修预约列表
    @InnerAuth
    @PostMapping("/getadd")
    public AjaxResult getAdd(@RequestBody CarRepairReservation carRepairReservation)
    {
        return toAjax(carRepairReservationService.insertCarRepairReservation(carRepairReservation));
    }
//  对外暴露接口  修改维修预约列表
    @InnerAuth
    @PutMapping("/getEdit")
    public AjaxResult getEdit(@RequestBody CarRepairReservation carRepairReservation)
    {
        return toAjax(carRepairReservationService.updateCarRepairReservation(carRepairReservation));
    }
//  对外暴露接口  删除维修预约列表
    @InnerAuth
    @DeleteMapping("/getRemove/{ids}")
    public AjaxResult getRemove(@PathVariable Long[] ids)
    {
        return toAjax(carRepairReservationService.deleteCarRepairReservationByIds(ids));
    }


    /**
     * 查询维修预约列表
     */
    @RequiresPermissions("yyq:reservation:list")
    @GetMapping("/list")
    public TableDataInfo list(CarRepairReservation carRepairReservation)
    {
        startPage();
        List<CarRepairReservation> list = carRepairReservationService.selectCarRepairReservationList(carRepairReservation);
        return getDataTable(list);
    }

    /**
     * 导出维修预约列表
     */
    @RequiresPermissions("yyq:reservation:export")
    @Log(title = "维修预约", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarRepairReservation carRepairReservation)
    {
        List<CarRepairReservation> list = carRepairReservationService.selectCarRepairReservationList(carRepairReservation);
        ExcelUtil<CarRepairReservation> util = new ExcelUtil<CarRepairReservation>(CarRepairReservation.class);
        util.exportExcel(response, list, "维修预约数据");
    }

    /**
     * 获取维修预约详细信息
     */
    @RequiresPermissions("yyq:reservation:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(carRepairReservationService.selectCarRepairReservationById(id));
    }

    /**
     * 新增维修预约
     */
    @RequiresPermissions("yyq:reservation:add")
    @Log(title = "维修预约", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarRepairReservation carRepairReservation)
    {
        return toAjax(carRepairReservationService.insertCarRepairReservation(carRepairReservation));
    }

    /**
     * 修改维修预约
     */
    @RequiresPermissions("yyq:reservation:edit")
    @Log(title = "维修预约", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarRepairReservation carRepairReservation)
    {
        return toAjax(carRepairReservationService.updateCarRepairReservation(carRepairReservation));
    }

    /**
     * 删除维修预约
     */
    @RequiresPermissions("yyq:reservation:remove")
    @Log(title = "维修预约", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(carRepairReservationService.deleteCarRepairReservationByIds(ids));
    }
}
